package com.xinsoft.controller.basic;

import com.xinsoft.common.Response;
import com.xinsoft.entity.po.SysClientLevel;
import com.xinsoft.service.SysClientLevelService;
import com.xinsoft.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/clientLevel")
public class SysClientLevelController {

    @Autowired
    private SysClientLevelService sysClientLevelService;

    /**
     * 新增
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/add")
    public Response<?> add(@RequestBody SysClientLevel sysClientLevel) {
        // 参数校验
        ValidatorUtils.validateEntity(sysClientLevel);
        return Response.succeed(sysClientLevelService.save(sysClientLevel));
    }

    /**
     * 更新
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/edit")
    public Response<?> edit(@RequestBody  SysClientLevel sysClientLevel) {
        // 参数校验
        ValidatorUtils.validateEntity(sysClientLevel);
        return Response.succeed(sysClientLevelService.updateById(sysClientLevel));
    }

    /**
     * 获取客户等级
     */
    @GetMapping("/detail")
    public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
        return Response.succeed(sysClientLevelService.getById(id));
    }

    /**
     * 删除
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/del")
    public Response<?> del(@RequestBody List<Integer> ids) {
        sysClientLevelService.removeByIds(ids);
        return Response.succeed();
    }

    /**
     * 列表
     */
    @PostMapping("/list")
    public Response<?> list() {
        return Response.succeed(sysClientLevelService.list());
    }
}
